'use strict';

module.exports = app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const sys_menu = app.model.define('sys_menu', {
    menuId: {
      type: INTEGER(20),
      comment: "菜单ID",
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
      field:"menu_id"
    },
    menuName: {
      type: STRING(50),
      comment: "菜单名称",
      allowNull: false,
      field:"menu_name"
    },
    parentId: {
      type: INTEGER(20),
      comment: "父菜单ID",
      defaultValue: 0,
      field:"parent_id"
    },
    orderNum: {
      type: INTEGER(4),
      comment: "显示顺序",
      defaultValue: 0,
      field:"order_num"
    },
    path: {
      type: STRING(200),
      comment: "路由地址"
    },
    component: {
      type: STRING,
      comment: "组件路径"
    },
    isFrame: {
      type: STRING(1),
      comment: "是否为外链（0是 1否）",
      defaultValue: "1",
      field:"is_frame"
    },
    isCache: {
      type: STRING(1),
      comment: "是否缓存（0缓存 1不缓存）",
      defaultValue: "0",
      field:"is_cache"
    },

    menuType: {
      type: STRING(1),
      comment: "菜单类型（M目录 C菜单 F按钮）",
      defaultValue: "",
      field:"menu_type"
    },
    visible: {
      type: STRING(1),
      comment: "菜单状态（0显示 1隐藏）",
      defaultValue: "0"
    },
    status: {
      type: STRING(1),
      comment: "菜单状态（0正常 1停用）",
      defaultValue: "0"
    },
    perms: {
      type: STRING(100),
      comment: "权限标识"
    },
    icon: {
      type: STRING(100),
      comment: "菜单图标",
      defaultValue: ""
    },
    createBy: {
      type: STRING(64),
      comment: "创建者",
      defaultValue: "",
      field:"create_by"
    },
    updateBy: {
      type: STRING(64),
      comment: "更新者",
      defaultValue: "",
      field:"update_by"
    },
    remark: {
      type: STRING(500),
      comment: "备注",
      defaultValue: ""
    },
    createTime: {
      type: DATE,
      comment: "创建时间",
      field:"created_at"
    }
  }, {
    paranoid: true,
    freezeTableName: true
  });

  sys_menu.associate = () => {
    app.model.SysMenu.belongsToMany(app.model.SysRole, {
      through: app.model.SysRoleMenu,
      allowNull:true
    });
    
  }

  return sys_menu;
};